﻿(function () {
    const utils = {
        /**从tree的当前节点开始，向上冒泡，直到指定的祖先节点（不包含），每个节点都执行一次回调，如果回调返回true，则终止冒泡。
         * @param {{parentNode:tree}} tree
         * @param {(node:tree)=>boolean} callback
         * @param {tree} parent
         */
        bubbleCall(tree, callback, parent) {
            if (tree === parent || callback(tree, UTILS)) return;
            this.bubbleCall(tree.parentNode, callback, parent);
        },
        addScripts(scripts) {
            [...scripts].forEach(function (script) {
                if (script.id) return;
                let node = document.createElement('SCRIPT');
                script.src
                    ? node.src = script.src
                    : node.innerHTML = script.innerHTML;
                node.type = script.type;
                script.replaceWith(node);
            });
        },
    };
    inject('utils', utils);
})()


